关于元素Id的jQuery中一个有趣的问题 [英] An interesting question in jQuery regarding element Id
问题描述
这是我表单中的一个简单的html文本框。
Here is a simple html textbox in my form.
<input type="text" class="form-control InteractionText" id="InteractionFinalText" />
现在当我在jQuery中访问此文本框值时,我没有通过这样的写入获得输入的值
Now when I am accessing this textbox value in jQuery I am not getting the value entered in it by writing like this
$(".InteractionText").value
(OR)
(OR)
$("#InteractionFinalText").value
有趣的是,当我这样访问时它工作正常,我为什么要通过Index值访问,以及为什么使用第二个索引,这是非常令人惊讶的。?
interestingly it is working fine when I am accessing like this, it was so surprising for me why we should access by Index value, moreover why with second index.?
$(".InteractionText")[2].value
请注意我确信在我的页面中只有一个带有InteractionText类的元素,当然如果我使用id访问我也面临同样的问题。?
我是否遗漏了jQuery基金中的任何简单点。或者是什么导致这种情况,任何帮助都会减轻我的头痛因为这个简单的问题我在网上浏览浪费我的时间。
Note that i am sure in my page only one element with class "InteractionText", of course if I access with id also I am facing the same issue.?
Is I am missing any simple point in fundas of jQuery.? Or what causes this kind of scenario, any help will reduce my headache because of this simple issue I am wasting my time by browsing in net.
推荐答案
(。InteractionText ).value
(".InteractionText").value
(或)
(OR)
(# InteractionFinalText)。value
("#InteractionFinalText").value
有趣的是,当我这样访问时工作正常,对我来说,为什么我们应该访问它是如此令人惊讶通过索引值,以及为什么使用第二个索引。?
interestingly it is working fine when I am accessing like this, it was so surprising for me why we should access by Index value, moreover why with second index.?
(。InteractionText )[2] .value
(".InteractionText")[2].value
请注意,我确信在我的页面中只有一个带有InteractionText类的元素,当然,如果我使用id访问,我也面临同样的问题。?
我是否缺少jQuery基金中的任何简单点。或者是什么导致这种情况,任何帮助都会减轻我的头痛,因为这个简单的问题我在网上浏览浪费时间。
Note that i am sure in my page only one element with class "InteractionText", of course if I access with id also I am facing the same issue.?
Is I am missing any simple point in fundas of jQuery.? Or what causes this kind of scenario, any help will reduce my headache because of this simple issue I am wasting my time by browsing in net.
这篇关于关于元素Id的jQuery中一个有趣的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!