javascript和dom树 [英] javascript and dom tree

查看:102
本文介绍了javascript和dom树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javascript搜索网站上的html文本.为了做到这一点,我正在使用dom树.我编写了代码以查看h4元素中包含的html,我可以看到它找到了所有6个标头(d.length警报),并且使用了chrome,我可以看到每个文本的textContext是我所期望的,但是我无法弄清楚访问h4元素的文本的语法(使用最后一个警报).请帮忙!!!!! (第三个警报仅访问第一个h4元素的文本)

I am trying to use javascript to search the html text on a website. In order to do this I am using the dom tree. i wrote code to look at the html contained in a h4 element, and i can see that it found all 6 headers(d.length alert), and using chrome, i can see the textContext of each is what i would expect, but i cannot figure out the syntax to access the text of the h4 element(using last alert). PLEASE HELP!!!!! (3rd alert only accesses text of first h4 element)

$(document).ready(function (e) {
        $('#submit').click(function (e) {
            try {
                var $inputTxt = $('#search');
                result = $inputTxt.val();
                alert(result);
                var d = $('h4');
                alert("load html");

                for (var i = 0; i < d.length; i++) {
                    alert(d.length);
                    alert($('h4').html());
                    alert($d[i].html().textContext);
                }
                if (d == result) {
                    alert("result found");
                } alert("got to end");
            } catch (ex) { e.preventDefault(); }
        });

推荐答案

(文档).ready(
(document).ready(function (e) {


( #submit').click(功能(e){ 尝试 { var
('#submit').click(function (e) { try { var


inputTxt =
inputTxt =


这篇关于javascript和dom树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆