我想将纯javascript转换为jquery,此代码将删除包含指定搜索文本的所有行。这是我的代码:
我在jsfiddle的代码:http://jsfiddle.net/v306rzhg/4
<body>
Search lines for:
<input type="text" id="addfield0" value="Sometimes|relevance|understand" style="width:100%; margin-top:10px;" />
<input type="button" style="margin-top:10px;" value="Remove Lines Containing..." onClick="if(document.getElementById('addfield0').value!='') {removelines('containing');}" />
<input type="button" value="Not Containing..." onClick="if(document.getElementById('addfield0').value!='') {removelines('notcontaining');}" />
<textarea id="input_output" style="width:100%; margin-top:10px; height:150px; resize:none;" wrap="off">Sometimes to understand a word's
meaning you need more than a definition.
At Your Dictionary we try to give you all of the tools
you need to really understand what the word means.
Seeing the word in a sentence can
provide more context and relevance.</textarea>
<textarea id="removed_box" rows="4" style="width:100%; margin-top:10px; height:150px; resize:none;" wrap="off"></textarea>
</body>
</html>
答案 0 :(得分:2)
Jquery
中的
这里是如何调用元素的;
而不是
document.getElementById('addfield0')
只需使用
$('#addfield0')
获取值时的示例:
$('#addfield0').val()
注意:请确保引用您的jquery
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>