JqGrid:尝试在“添加”的右侧添加一个+按钮。表单字段(使用elmsuffix) [英] JqGrid: Trying to add a + button to the right of a "add" form field (using elmsuffix)
问题描述
我可以显示图标,如果我将javascript行放在href中但是我无法将对话框对象附加到链接ID,它会触发一个简单的警告。
I can get the icon to show up, and it fires a simple alert if I place the javascript line in the href but I cannot attach a dialog object to the link id.
我正在使用elmsuffix来获取html:
I am using "elmsuffix" to get the html there:
这有效:
{name:'name',index:'name',width:100, editable: true, formoptions:{elmsuffix: "<a id="companysearch" href="javascript:alert('yay it worked!');" ><span id="companysearchicon" class="ui-icon ui-icon-plus" style="position:absolute; top:2px; right:25px; "></span></a>"}},
这不是:
$("#companysearch").click(function(){ alert('yay it worked!'); });
{name:'name',index:'name',width:100, editable: true, formoptions:{elmsuffix: "<a id="companysearch" href="javascript:void(0)" ><span id="companysearchicon" class="ui-icon ui-icon-plus" style="position:absolute; top:2px; right:25px; "></span></a>"}},
它几乎就像范围阻止对象相互协作(或者我只是简单地接近它)
Its almost like the scopes are preventing the objects to work with each other (or am I just plain, approaching it wrongly)
谢谢
Andrew Finegan
Andrew Finegan
推荐答案
首先,我想你使用 elmsuffix:'< a id = companysearch...'
而不是 elmsuffix:< a id =companysearch...
在没有转义的情况下拥有正确的语法每个个字符。
First of all I suppose you use elmsuffix: '<a id="companysearch" ...'
and not elmsuffix: "<a id="companysearch" ..."
to have correct syntax without escaping every "
characters.
您使用<$时<问题> c $ c> $(#companysearch)。点击(...)。目前,id =companysearch的元素必须已存在于页面的DOM中。所以你应该要么在之内使用beforeShowForm
事件处理程序:
The problem from your question is when you use $("#companysearch").click(...)
. At the moment the element with id="companysearch" must already exist in DOM of the page. So you should either use in inside of beforeShowForm
event handler:
$("#list").jqGrid('navGrid','#pager',{},
{ // edit options
beforeShowForm: function(form) {
$("#companysearch").click(function(){
alert('yay it worked!');
});
}
});
或使用 jQuery.live 方法:
$("#companysearch").live('click', function() {
alert('yay it worked (live)!');
});
In the small example you can see live both the ways working.
这篇关于JqGrid:尝试在“添加”的右侧添加一个+按钮。表单字段(使用elmsuffix)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!