javascript 使用用户输入更新 div
可能的重复:
Javascript 在点击时更改 div 内容
我想要做什么 更新原始测试
<div class="show">
是让这段代码用用户放置的内容
<style type="text/css">
/* Normal mode */
.weight-display div.edit {display:none}
/* Editor mode */
.weight-edit div.show {display:none}
</style>
<div class="weight-display">
<button onclick="toggle(this)">Edit this!</button>
<div class="edit"><select name="Category">
<option value="Department">Department</option>
<option value="Accounts">Accounts</option><option value="Claims">HR</option><option value="Yachts UW">IT</option><option value="Marine Trade">Marketing</option></select></div>
<div class="show">Test</div>
</div>
<script type="text/javascript">
function toggle(button)
{
// Change the button caption
button.innerHTML = button.innerHTML=='Edit this!' ? 'Save' : 'Edit this!';
// Change the parent div's CSS class
var div = button.parentNode;
div.className = div.className=='weight-display' ? 'weight-edit' : 'weight-display';
}
</script>
。原始:原始
Possible Duplicate:
Javascript change div content upon a click
What I'm trying to do is have this code update the original Test
<div class="show">
with what the user has put there.
<style type="text/css">
/* Normal mode */
.weight-display div.edit {display:none}
/* Editor mode */
.weight-edit div.show {display:none}
</style>
<div class="weight-display">
<button onclick="toggle(this)">Edit this!</button>
<div class="edit"><select name="Category">
<option value="Department">Department</option>
<option value="Accounts">Accounts</option><option value="Claims">HR</option><option value="Yachts UW">IT</option><option value="Marine Trade">Marketing</option></select></div>
<div class="show">Test</div>
</div>
<script type="text/javascript">
function toggle(button)
{
// Change the button caption
button.innerHTML = button.innerHTML=='Edit this!' ? 'Save' : 'Edit this!';
// Change the parent div's CSS class
var div = button.parentNode;
div.className = div.className=='weight-display' ? 'weight-edit' : 'weight-display';
}
</script>
original: Original
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,如果我理解正确的话,您想从下拉列表中获取所选值并将该值设置为 div.show 吗?
在这种情况下,你可以这样做 http://jsfiddle.net/f9mBm/3/
Ok so if I understand you correctly you want to get the selected value from the dropdown and set that value to the div.show ?
In that case you can do something like this http://jsfiddle.net/f9mBm/3/