如何使用RegisterStartupScript调用jquery对话框? [英] how to call jquery dialog using RegisterStartupScript?
问题描述
我有以下vb.net,并且运行良好
I have the following vb.net and it is working great
Public Shared Sub createAlert(ByVal page As Page, ByVal msg As String)
msg = msg.Replace(vbCrLf, "\n").Replace("'", "\'")
page.ClientScript.RegisterStartupScript(page.GetType, "clientScript", "<script language='javascript'>alert('" & msg & "');</script>")
End Sub
现在,我想实现此 http://jsfiddle.net/WrdM9/2/ .这是一个3秒钟后自动关闭的jquery对话框
Now I would like to implement this http://jsfiddle.net/WrdM9/2/ . it is a jquery dialog with auto close after 3 seconds
我尝试了以下方法,但是没有运气 我究竟做错了什么?
I have tried the following to no luck What am I doing wrong?
Public Shared Sub AlertAutoClose(ByVal page As Page, ByVal msg As String)
Dim sScript As String
sScript = "<script src=""js/jquery.js"">$(document).ready(function(){$('#dialog').html('some message');});"
sScript += "$(document).ready(function(){$('#dialog').dialog({"
sScript += "autoOpen: true,"
sScript += "show: ""blind"","
sScript += "hide: ""explode"","
sScript += "modal: true,"
sScript += "open: function(event, ui) {"
sScript += "setTimeout(function(){"
sScript += "$('#dialog').dialog('close'); "
sScript += "}, 3000);"
sScript += "}"
sScript += "});});</script>"
msg = msg.Replace(vbCrLf, "\n").Replace("'", "\'")
page.ClientScript.RegisterStartupScript(page.GetType, "Script", sScript)
End Sub
推荐答案
当您在脚本标签中引用src ="js/jquery.js"这样的脚本文件时,脚本标签之间的内容将不会执行,并且从技术上讲是非法的.因此,您只需要将其分解为一个单独的脚本标签即可.这将起作用:
When you reference a script file in your script tag like src="js/jquery.js", what's in between the script tag will not be executed and it's technically illegal. So you just need to break that out into a separate script tag. This will work:
<script src="js/jQuery.js"></script>
<script type="text/javascript">
alert('test');
</script>
这不会:
<script src="js/jQuery.js">
alert('test');
</script>
这篇关于如何使用RegisterStartupScript调用jquery对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!