更新面板和 Javascript
我有这样的内联脚本,它可以在编辑和显示 div 之间切换。如果它位于 UpdatePanel 内部,则需要单击两次才能工作。如果我删除 UpdatePanel,只需单击一下即可正常工作。
<a href="#" onclick="edit(event,'ctl00_CPH1_ctl00_win1')">Edit</a>
有人可以帮忙吗?
谢谢
编辑: 编辑功能:
function edit(e, id) {
var editdiv = $('#' + id).find('.edit');
var cntdiv = $('#' + id).find('.content');
if (editdiv.css('visibility') == 'hidden') {
editdiv.css('visibility') == 'visible'
cntdiv.css('visibility') == 'hidden'
cntdiv.hide();
editbox.show()
}
else {
editdiv.css('visibility') == 'hidden'
cntdiv.css('visibility') == 'visible'
cntbox.show();
editbox.hide()
}
stopEventBubble(e); // Code to cancel event bubbling;
}
I have inline script such as this, which toggles between an edit and a display divs. If it is inside the the UpdatePanel it requires two click before it works. If I remove the UpdatePanel it works fine with a single click.
<a href="#" onclick="edit(event,'ctl00_CPH1_ctl00_win1')">Edit</a>
Can anyone help please?
Thanks
EDIT:
Edit function:
function edit(e, id) {
var editdiv = $('#' + id).find('.edit');
var cntdiv = $('#' + id).find('.content');
if (editdiv.css('visibility') == 'hidden') {
editdiv.css('visibility') == 'visible'
cntdiv.css('visibility') == 'hidden'
cntdiv.hide();
editbox.show()
}
else {
editdiv.css('visibility') == 'hidden'
cntdiv.css('visibility') == 'visible'
cntbox.show();
editbox.hide()
}
stopEventBubble(e); // Code to cancel event bubbling;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否使用ScriptManager来注册编辑功能?
如果您的代码位于外部文件中,您可以在页面的 aspx 中使用 ScriptManager 或 ScriptManagerProxy 注册它:
编辑:
好吧,我现在知道问题是什么了。您一开始就没有设置 css 可见性。因此,您需要设置 css 可见性,或者可以修改编辑功能以遵循以下逻辑:
另一个选项将要求您在“编辑”和“内容”div 中设置以下内容。
如果您需要进一步的帮助,我需要查看您有关 UpdatePanel、编辑和内容的 aspx 代码。
Are you using the ScriptManager to register the edit function?
If your code is in an external file, you can register it with the ScriptManager or the ScriptManagerProxy in the aspx for your page:
EDIT:
alright, I know what the issue is now. You aren't setting the css visibility to begin with. So either you need to set the css visibility or you can modify your edit function to follow the following logic:
The other option will require you to set the following in you "edit" and "content" divs.
If you need further help, I'll need to see your aspx code concerning the UpdatePanel, edit, and content.
试试这个:
编辑
作为 克里斯 说:
如果您在单击“编辑”链接时注入该函数,则该函数在您第一次单击“编辑”链接时将不存在。
您可以做的是将函数添加到标记的
部分的
标记内:
或者添加到单独的 .js 文件中。
Try this:
Edit
As Chris said:
If you are injecting the function when you click the Edit link the function won't exist the first time you click an Edit link.
What you could do is add the function inside a
<script>
tag in the<head>
section of the markup:Or in a separate .js file.