就像我在问题中所说的...有没有办法点击复选框,该链接将更改为 http://youtu.be/kffacxfA7G4
?
代码示例:
<div class="embed-code">
<textarea rows="" cols="">http://www.youtube.com/watch?v=kffacxfA7G4</textarea>
<label>
<input type="checkbox" />
Short URL</label>
</div>
我认为这可以用 javascript/jquery 来完成...
有人在用吗?提前致谢...
编辑:
我已经设法做到了:http://jsfiddle.net/tpLfS/
$('#myCheckBox').click(function(){ var myLink = $('#myTextarea');
if ($('#myCheckBox:checked').val() !== undefined){ //checked
myLink.val(myLink.val().replace('http://www.youtube.com/watch?v=kffacxfA7G4','http://youtu.be/kffacxfA7G4'));}
else { //not checked
myLink.val(myLink.val().replace('http://youtu.be/kffacxfA7G4','http://www.youtube.com/watch?v=kffacxfA7G4'));}
})
可以轻松完成吗?
最佳答案
查询非常简单:首先你需要给你的复选框和文本区域一个id:
<textarea rows="" cols="" id="myTextarea">...</textarea>
<input id="myCheckBox" type="checkbox" />
然后添加 javascript 部分(在我使用 jQuery 的示例中): 我不确定您想如何更改它。我想你只是想删除 "watch?v="
$('#myCheckBox').click(function(){
var myLink = $('#myTextarea');
myLink.val(myLink.val().replace('watch?v=',''));
})
关于html - 我该怎么做才能单击 html 复选框并更改 html 输入的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12097200/