简体   繁体   English

jQuery .text无法正常工作,但是.val可以吗?

[英]jQuery .text not working, but .val does?

I have the code working in jsfiddle but when i implement the code into my solution it does not do anything. 我的代码在jsfiddle中工作,但是当我在解决方案中实现代码时,它什么也没做。

When checkboxes are checked the idea is that it populates a comma seperated list of all items that have been checked into a div. 选中复选框时,其想法是将所有已签入div的项目填充以逗号分隔的列表。 However this does not work, but it works for a textarea fine? 但是,这不起作用,但是它可以用于textarea罚款吗?

http://jsfiddle.net/uJcB7/166/ http://jsfiddle.net/uJcB7/166/

This is the line in question: 这是有问题的行:

 $('#standardFitFeatures').text(allVals)

Then I give the div then ID: 然后我给div然后ID:

<div id="standardFitFeatures"></div>

This wont work at all, I have to create a textarea and change .text to to val 这根本行不通,我必须创建一个textarea并将.text更改为val

Any idea why and how I can sort this as I need it to populate the div? 知道为什么以及如何在需要填充div时对其进行排序吗?

put

$('#cblistp input').click(updateTextArea);
 updateTextArea();

and

 $('#cblistStatic input').click(updateTextAreaW);
 updateTextAreaW();

inside $(document).ready() if you want a consistent behavior $(document).ready()如果您想要一致的行为

it is highly likely that you are binding events to elements that don't yet exist. 您很有可能将事件绑定到尚不存在的元素。

EDIT 编辑

.val() works for TextArea and Input whereas .Text() works for DIV ... Please check if you are indeed using Div in the production code and not textarea. .val()适用于TextAreaInput.Text()适用于DIV ...请检查您是否确实在生产代码中使用Div而不是textarea。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM