我需要用输入的文本更改DOMnodes中的所有文本。我该怎么做呢?
$('#lc-change-all-values').keyup(function(){
$('body *').text($(this).val())// How I can do it?
});此代码应允许在任何网页上使用。我使用的是google chrome扩展。我的HTML:
<h1>BrowsingData API Sample</h1>
<div role="main">
<form>
<label for="timeframe">Remove all browsing data from:</label>
<select id="timeframe">
<option value="hour">the past hour</option>
<option value="day">the past day</option>
<option value="week">the past week</option>
<option value="4weeks">the past four weeks</option>
<option value="forever">the beginning of time</option>
</select>
<button id="button">OBLITERATE!</button>
</form>
</div>我需要像这样得到html代码:
<h1>My text</h1>
<div role="main">
<form>
<label for="timeframe">My text</label>
<select id="timeframe">
<option value="hour">My text</option>
<option value="day">My text</option>
<option value="week">My text</option>
<option value="4weeks">My text</option>
<option value="forever">My text</option>
</select>
<button id="button">My text</button>
</form>
</div>发布于 2015-05-30 23:05:03
请注意,html?中没有显示#lc-change-all-values?
将<input type="text" id="lc-change-all-values" />添加到html;特别选择了将#lc-change-all-values value设置为使用.text()的元素
$("#lc-change-all-values").keyup(function() {
$("h1, button, label, select option")
.text(this.value)
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<body>
<input type="text" id="lc-change-all-values" />
<h1>BrowsingData API Sample</h1>
<div role="main">
<form>
<label for="timeframe">Remove all browsing data from:</label>
<select id="timeframe">
<option value="hour">the past hour</option>
<option value="day">the past day</option>
<option value="week">the past week</option>
<option value="4weeks">the past four weeks</option>
<option value="forever">the beginning of time</option>
</select>
<button id="button">OBLITERATE!</button>
</form>
</div>
</body>
https://stackoverflow.com/questions/30547649
复制相似问题