Javascript 如何在jquerymobile中使用js在li中获取价值
单击该按钮时,我以登录身份登录Javascript 如何在jquerymobile中使用js在li中获取价值,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,单击该按钮时,我以登录身份登录 $(document).on("click", "#bizParams", function(e) { $("#span1").find("li").each(function(){ var product = $(this); // rest of code. console.log(product); }); }); 我必须得到value1和value2的值 有人能说出这里出了什么问题吗 console.lo
$(document).on("click", "#bizParams", function(e) {
$("#span1").find("li").each(function(){
var product = $(this);
// rest of code.
console.log(product);
});
});
我必须得到value1和value2的值
有人能说出这里出了什么问题吗
console.log(product.text())代码>
(这是普通的jQuery)如果要获取text()
属性,而不是整个对象,请更改以下内容:
Object[li.ui-li-static.ui-body-inherit.ui-first-child]
Object[li.ui-li-static.ui-body-inherit.ui-last-child]
为此:
console.log(product);
这条线有问题
console.log(product.text());
你必须提取文本
var product = $(this);
您应该使用:
$("#myid li").click(function() {
alert(this.id); // id of clicked li by directly accessing DOMElement property
alert($(this).attr('id')); // jQuery's .attr() method, same but more verbose
alert($(this).html()); // gets innerHTML of clicked li
alert($(this).text()); // gets text contents of clicked li
});
但在此之前,将id=“bizParams”
添加到按钮
$(document).on("click", "#bizParams", function(e) {
$("#span1").find("li").each(function(){
var product = $(this);
// rest of code.
console.log(product.text());
});
});
DOM结构中的#bizParams
在哪里???有一个按钮,但我忘了添加它,除了向按钮添加idbizParams
之外。。。没有必要在()上使用.on()
(事件委派)这里,当我们在DOM中动态添加html时,应该使用它。。。您可以在此处使用simple。click()
。@keerthanalivelui没有更改它,因为它没有做任何错误。
$("#myid li").click(function() {
alert(this.id); // id of clicked li by directly accessing DOMElement property
alert($(this).attr('id')); // jQuery's .attr() method, same but more verbose
alert($(this).html()); // gets innerHTML of clicked li
alert($(this).text()); // gets text contents of clicked li
});
$(document).on("click", "#bizParams", function(e) {
$("#span1").find("li").each(function(){
var product = $(this);
// rest of code.
console.log(product.text());
});
});
<input type="button" id="bizParams"value="Add params to list" />