[英]insert text into textarea when option selected
I need your help. 我需要你的帮助。 I'm trying to insert some text into a textarea-element when the url contains 'number' and an option with value='option2' of a selectbox is selected.
当URL包含“数字”并且选择了一个selectbox的值为“ option2”的选项时,我试图将某些文本插入到textarea元素中。
var contentToInsert = 'Text';
if (location.href.indexOf("/number")) {
if (value of selectbox == 'option2') {
$("textarea").append(contentToInsert);
}
}
How do I check when the option is selected? 如何检查选择了该选项的时间? The text to insert shouldn't be shown when another option is selected.
选择其他选项时,不应显示要插入的文本。 So this would mean that I need on event-handler like onchange.
所以这意味着我需要像onchange这样的事件处理程序。
Have you got an idea? 你有个主意吗?
Are you sure this line of your code is right? 您确定这行代码正确吗?
$("textarea").append(contentToInsert);
If you are referring to a tag with the id "textarea" then maybe it should be: 如果您引用的ID为“ textarea”的标签,则可能是:
$("#textarea").append(contentToInsert);
Not to mention this will append to that id tag a child node. 更不用说这将在该id标签后附加一个子节点。
Hope it helps :) Cheers! 希望对您有所帮助:)干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.