没看出什么问题你贴出来的代码。最好是贴全来。。
if ($.isFunction(callback)) {alert(callback)//输出回调函数体看看都一样没有,一样应该是其他代码覆盖过callback什么的了
callback(rowData);
$('#GoodsQueryWin').window('close');
}
if ($.isFunction(callback)) {alert(callback)//输出回调函数体看看都一样没有,一样应该是其他代码覆盖过callback什么的了
callback(rowData);
$('#GoodsQueryWin').window('close');
}
a.b = function(callback){
callback("1");
}
function t1(){
a.b(function(str){
document.getElementById("name").value = str;
})
}
function t2(){
a.b(function(str){
document.getElementById("age") .value = str;
})
}
//两个方法同时调用后,修改的都是 id=name的input。
//请问一下怎么才能够使得 name 和 age 都得到那个值呢?
//谢谢啊!
我自己琢磨了一下 应该i是这个问题。。 但是我不知道怎么解决。。
继承function 什么的可以吗? 0 0
$("#goodsNumImg").on('click',function(event){
alert(100);
$('#goodsNum').val(100);
})
//赠送商品编号
$("#zEitmImg").on('click',function(event){
alert(200)
$('#zEitm').val(200);})先证明你的 button事件触发后 input的处理是正确的
然后 我们在来看 GoodsQueryWin
<script>
var a = {}
a.b = function (callback) {
callback("1");
} function t1() {
a.b(function (str) {
document.getElementById("name").value = str;
})
} function t2() {
a.b(function (str) {
document.getElementById("age").value = str;
})
}
t1()
t2()
</script>没有问题啊设置的是不同的input。。
$.StoreQueryWin = function(callback){
if($('#StoreQueryWin').length == 0){
var winEl = $('<div id="StoreQueryWin" title="My Window"></div>');
var layout = $(' <div id="storeqWinLayout" data-options="fit:true"></div>');
var northEl = $('<div data-options="region:\'north\',border:0" style="height:50px;padding-top:15px;border-bottom:1px solid #dcdcdc;"><form id="searchStoreForm"><table><tr><td class="field"> 仓库/店铺编号:</td><td><input id="mystoreno" name="storeno" type="text" style="width:120px;"/> </td><td class="field"> 仓库/店铺名称:</td><td><input id="myStoreName" name="storeName" type="text" style="width:120px;"/> </td><td> <a href="javascript:void(0);" class="easyui-linkbutton" onclick="seachFn();">过滤</a> <a href="javascript:void(0);" class="easyui-linkbutton" onclick="cleanSearch();">取消</a></tr></table></form></div> ');
var centerEl = $('<div data-options="region:\'center\',border:0"><table id="StoreQueryList"></table></div>');
northEl.appendTo(layout);
centerEl.appendTo(layout);
layout.appendTo(winEl);
winEl.appendTo('body');
$('#StoreQueryWin').window({
title : '仓库/店铺信息查询',
width:600,
height:400,
modal:true
});
$('#storeqWinLayout').layout();
$('#StoreQueryList').datagrid({
url: $basePath + '/store/queryStoreByList.html',
fit : true,
pageList : [15,30,50],
border:false,
nowrap: true,
autoRowHeight: false,
striped: false,
collapsible:false,
remoteSort: false,
pagination:true,
rownumbers:true,
singleSelect:true,
columns:[[
{field:'storeno',title:'仓库/店铺编号',align:'center',width:150,sortable:true},
{field:'storeName',title:'仓库/店铺名称',align:'center',width:150,sortable:true}
]],
onDblClickRow : function(rowIndex, rowData){
if($.isFunction(callback)){
callback(rowData);
$('#StoreQueryWin').window('close');
}
}
});
}else{
$('#StoreQueryWin').window('open');
}
seachFn=function(){
$('#StoreQueryList').datagrid('load', sy.serializeObject($('#searchStoreForm')));
}
cleanSearch=function(){
$('#StoreQueryList').datagrid('load',{});
$('input[name="storeno"]').val("");
$('input[name="storeName"]').val("");
}
$('#mystoreno,#myStoreName').keydown(function(event){
if(event.keyCode==13){
$('#StoreQueryList').datagrid('load', sy.serializeObject($('#searchStoreForm')));
}
});
};
这个是整个GoodsQueryWin 。 是不是因为是同一个 form ,所以才这样的?
这个我试了一下。。弹出来和手动复制是可以的。但是调用 GoodsQueryWin 就不行了。。
那应该是我的GoodsQueryWin 这个的问题。。 是不是form表单有问题哦0 0.!
...onDblClickRow : function(rowIndex, rowData){
if($.isFunction(tmpcallback)){
tmpcallback(rowData);
$('#StoreQueryWin').window('close');
}
}你的本意不会是 希望 不同的打开按钮 注册 不同的回调吧
这样的话 你原来的写法 根据 闭包 第一次 初始化的时候 onDblClickRow 关联了 第一次的callback
第2次callback 其实被无视了
var tmpcallback;$.StoreQueryWin = function(callback){ tmpcallback = callback;
改称这样 tmpcallback 脱离当前的闭包