动态调用时零剪贴板不起作用
当以这种形式使用时,代码工作得非常好。
<div id="d_clip_button" style="background: #FFFFCC;">
Click to copy
</div>
<script language="JavaScript" type="text/javascript">
var clip = new ZeroClipboard.Client();
clip.setText( '<?php echo "http://example.com/" . $var; ?>' );
clip.glue( 'd_clip_button' );
</script>
当上面的代码像这样动态调用时会出现问题:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
<form action="generar.php" method="post">
Input: <input type="text" id="longUrl" name="longUrl" value="" /><br />
<input type="button" value="Acortar!" onclick="submitme()" />
<div id="resultado"></div>
</form>
<script type="text/javascript" charset="utf-8">
function submitme(){
var tosend=document.getElementById("longUrl").value;
$.ajax({
type: 'POST',
url: 'generar.php',
data: 'longUrl='+tosend,
success: function(msg){
if(msg){
document.getElementById("resultado").innerHTML=msg;
}
else{
return;
}
}
});
}
</script>
出现“单击复制”,但资源未正确调用,因为它“不是闪存”。
关于如何进行这项工作有什么想法/问题是什么?
提前致谢!!请询问任何需要澄清的问题!
它是否与嵌套在 div
上的整个内容有任何关系(不这么认为)?
For coping to the clipboard I'm using Zero Clipboard, recommended by this answer.
The code works perfectly fine when used in this form.
<div id="d_clip_button" style="background: #FFFFCC;">
Click to copy
</div>
<script language="JavaScript" type="text/javascript">
var clip = new ZeroClipboard.Client();
clip.setText( '<?php echo "http://example.com/" . $var; ?>' );
clip.glue( 'd_clip_button' );
</script>
A problem occurs when this above code is called dynamically like this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
<form action="generar.php" method="post">
Input: <input type="text" id="longUrl" name="longUrl" value="" /><br />
<input type="button" value="Acortar!" onclick="submitme()" />
<div id="resultado"></div>
</form>
<script type="text/javascript" charset="utf-8">
function submitme(){
var tosend=document.getElementById("longUrl").value;
$.ajax({
type: 'POST',
url: 'generar.php',
data: 'longUrl='+tosend,
success: function(msg){
if(msg){
document.getElementById("resultado").innerHTML=msg;
}
else{
return;
}
}
});
}
</script>
The "Click to copy" appears but the resource is not called correctly since it's "not flash".
Any ideas on how to make this work / what is the problem?
Thanks in advance!! Please ask for any clarification needed!
Could it have (don't think so) anything to do with the whole thing being nested on a div
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
innerHTML
不执行 Ajax 调用中传递的 JavaScript。使用 jQuery 的
.html()
。innerHTML
doesn't execute JavaScript that gets passed through in the Ajax call.Use jQuery's
.html()
.