带Razor View的MVC动态添加按钮 [英] MVC with Razor View dynamically add button
问题描述
我有一个包含导航页脚的母版页(MasterLayout.cshtml)
I have a master page (MasterLayout.cshtml) that has footer with navigation
<div id="back_footer_button_placeholder"></div>
在加载的另一个页面中,我只需用
In another page when it loads I just replace that placeholder with
$("#next_footer_button_placeholder").html("<a class='button' title='Edit' href='java<!-- no -->script:return false;' önclick='nextBenefit();'><span class='icon_enrollnow'>Next</span></a>");
当我点击按钮时,它第一次不起作用但仅在第二次工作但是如果我用这个替换上面的代码
When I click the button it does not work the first time but works on the second time ONLY however if I replace the above code with this
<a class="button" title="Edit" href="java<!-- no -->script:return false;" önclick="nextBenefit();"><span class="icon_enrollnow">Next</span></a>
它适用于第一次点击。
我的问题是为什么它这样做?还有另一种方法,更简单的方法来替换页脚中的按钮吗?
谢谢。
It works on the first click.
My question is this why it does that? And is there another way, an easier way, to replacing buttons in the footer?
Thank you.
推荐答案
(#next_footer_button_placeholder)。html(< a class ='button'title ='Edit'href ='java<! - no - > script:return false;'önclick='nextBenefit( );'>< span class ='icon_enrollnow'>下一个< / span>< / a>);
("#next_footer_button_placeholder").html("<a class='button' title='Edit' href='java<!-- no -->script:return false;' önclick='nextBenefit();'><span class='icon_enrollnow'>Next</span></a>");
当我点击按钮时它第一次不起作用,但仅在第二次工作但是如果我用这个代替上面的代码
When I click the button it does not work the first time but works on the second time ONLY however if I replace the above code with this
<a class="button" title="Edit" href="java<!-- no -->script:return false;" önclick="nextBenefit();"><span class="icon_enrollnow">Next</span></a>
它适用于第一次点击。
我的问题是为什么它这样做?还有另一种方法,更简单的方法来替换页脚中的按钮吗?
谢谢。
It works on the first click.
My question is this why it does that? And is there another way, an easier way, to replacing buttons in the footer?
Thank you.
无关紧要将代码放在服务器端的位置,因为它在单个http结果文件中呈现。所以一切都取决于客户端。试试这个代码:
Does not matter where you put your code on server side, since it is rendered in a single http result file. So everything depends on the client side. Try this code:
<html>
<head>
<script src="http://codeorigin.jquery.com/jquery-1.10.2.min.js"></script>
<script>
function nextBenefit() {
alert("function called");
}
( function (){
这篇关于带Razor View的MVC动态添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!