将纯javascript转换为jquery

Convert pure javascript to jquery

本文关键字:jquery 转换 javascript 将纯      更新时间:2023-09-26

我想将纯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>

Jquery

以下是如何调用元素;

而不是

document.getElementById('addfield0')

只需使用

$('#addfield0')

获取值时的示例:

 $('#addfield0').val()

注意:确保您引用了您的jquery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>

在此处向下查询