从代码隐藏调用.js文件函数
Calling .js file function from code behind
我一直在尝试从代码隐藏调用.js文件函数,但没有调用函数。
我有以下 html 按钮,需要从后面的代码中可见。
<input id="btnShowMap" type="button" value="Results On Map" onclick = "ShowMap();" style="visibility: hidden;"/>
到目前为止,我已经尝试了以下三种方法,但没有一种有效。
-ClientScript.RegisterStartupScript(Me.GetType(), "VoteJsFunc", "test();")
-Page.ClientScript.RegisterStartupScript(Me.[GetType](), "VoteJsFunc", "alert('Sorry.You are not legible to vote')", True)
-ClientScript.RegisterStartupScript(Me.GetType(), "VoteJsFunc", "test();")
这是.js文件功能
function test() {
var hdLat = $('input[id$=hdVendorLat]').val();
var hdLng = $('input[id$=hdVendorLng]').val();
if (hdLat != 0 && hdLng != 0) {
$('#btnShowMap').show();
}
else {
$('#btnShowMap').hide();
}
}
这是 pahe html
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="updSearch" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" />
</Triggers>
<ContentTemplate>
<asp:HiddenField ID="hdVendorLat" runat="server" Value="0" />
<asp:HiddenField ID="hdVendorLng" runat="server" Value="0" />
<asp:HiddenField ID="hdVenID" runat="server" Value="" />
<asp:Panel ID="pnlExport" runat="server" Enabled="true">
<asp:Button ID="btnSearch" runat="server" Text="Search" Width="90px" />
<input id="btnShowMap" type="button" value="Results On Map" onclick = "ShowMap();" style="visibility: hidden;" />
</asp:Panel>
<script type="text/javascript" src="/scripts/inspector-search.js"></script>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
尝试注册脚本,如下所示:
Page.ClientScript.RegisterStartupScript(GetType(), "VoteJsFunc", "test()", True)
我在本地检查了一下,工作正常。
jQuery 方法show
适用于display
css 属性。相当于调用.css( "display", "block")
。
由于您使用的是visibility
属性,因此方法 show
对更改此属性没有影响,因此它保持隐藏状态。我看到 2 个选项可以解决此问题:
-
使用
.css( "visibility", "visible")
而不是.show()
-
将
style="visibility: hidden;"
替换为输入标记上的style="display: none"
在
调用调用函数的脚本之前,您只需要在 html 中调用上述.js文件。如果您需要更多信息,请提供您的 HTML 代码。
相关文章:
- 通过Ajax将JavaScript函数传递给PHP文件
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- 如何在 javascript 文件函数中找到 Radnotification id
- 对另一个文件函数的引用
- 从代码隐藏调用.js文件函数
- 如何javascript调用iframe加载的文件函数
- Javascript外部文件函数赢得'我以前不工作
- 读取本地文本文件函数不返回字符串类型,而是返回一个void类型
- 如何使用javascript在同一位置编辑和保存计算机中的任何文本文件.函数调用时,
- 如何用javascript调用jar文件函数
- 从SharePoint 2013脚本编辑器调用外部javascript文件函数
- 优先使用JS文件函数而不是HTML文件
- 如何从页面后面的代码调用js文件函数
- 外部JS文件's函数在无限滚动后不加载
- 在HTML按钮点击事件上调用jquery文件函数
- 在Angular js控制器中调用外部js文件函数
- Webpack主javascript文件's函数不能在加载在页脚的js文件中访问
- 我的jquery文档准备函数不能识别外部js文件函数
- 调用selenium-ide中的js文件函数
- 在RegisterStartupScript方法中使用外部Javascript文件函数