我点击按钮时使用window.open()
生成一个弹出窗口。
$.get(url).success(function(req) {
var win=window.open('popup.html', '', 'width=700, height=500, top=0, left(screen.width-700)');
win.document.write(req);
我在弹出窗口中有一个可编辑的字段,但它不起作用。我正在尝试这样的事情,
$.fn.editable.defaults.mode = 'popup';
for (var i=0; i<14; i++)
{
fieldname = "#sentiment_editable" + i
$(fieldname).editable({
inputclass: 'input-large',
source:[
{value:'positive', text: 'positive'},
{value:'neutral', text: 'neutral'},
{value:'negative', text: 'negative'}
]
});
}
win.document.close();
});
字段名称(标记ID)来自ajax响应(req)。 在popup.html中,我包含了以下库:
<script type="text/javascript" src="/js/jqueryui-editable.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jqueryui-editable.css" />
请求内容是这样的,
<script type="text/javascript" src="/js/jqueryui-editable.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jqueryui-editable.css" />
<div id="chatterpage" class="contentArea">
<div id="allsocial" >
<div id="all_container">
<div id="eachchatter1" class="socialcontentdiv" onmouseover="document.getElementById('chatterbuttons1').style.display='block'" onmouseout="document.getElementById('chatterbuttons1').style.display='none'">
<table border=0 width=100%>
<tr>
<td width=60%>
<span class="socialcontent1bold">Mood: </span>
<span class="socialcontent1">
<a data-original-title="Select sentiment" data-pk="1" data-url="/Handler" data-params='{chatterid: "5625665ba40e3cbef58de56a758d373d"}' data-type="select" data-value="neutral" id="sentiment_editable1" style="cursor:pointer" >neutral</a>
</span></td></tr>
<tr>
<td width=60%>
<span class="socialcontent1bold">Mood: </span>
<span class="socialcontent1">
<a data-original-title="Select sentiment" data-pk="1" data-url="/Handler" data-params='{chatterid: "fff3878b2d0e6849e9ee8408e7999892"}' data-type="select" data-value="neutral" id="sentiment_editable2" style="cursor:pointer" >neutral</a>
</span></td></tr>
</table>
</div><br/>
</div>
</div>
</div>
请帮帮我。
答案 0 :(得分:0)
我以前的回答是不正确的,所以我会尝试另外一次,在popup.html中添加对jquery库的引用,并添加你试图执行的脚本。
<link rel="stylesheet" type="text/css" href="/css/jqueryui-editable.css" />
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jqueryui-editable.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.fn.editable.defaults.mode = 'popup';
for (var i=0; i<14; i++)
{
fieldname = "#sentiment_editable" + i
$(fieldname).editable({
inputclass: 'input-large',
source:[
{value:'positive', text: 'positive'},
{value:'neutral', text: 'neutral'},
{value:'negative', text: 'negative'}
]
});
}
});
</script>
<div id="chatterpage" class="contentArea">
<div id="allsocial" >
<div id="all_container">
<div id="eachchatter1" class="socialcontentdiv" onmouseover="document.getElementById('chatterbuttons1').style.display='block'" onmouseout="document.getElementById('chatterbuttons1').style.display='none'">
<table border=0 width=100%>
<tr>
<td width=60%>
<span class="socialcontent1bold">Mood: </span>
<span class="socialcontent1">
<a data-original-title="Select sentiment" data-pk="1" data-url="/Handler" data-params='{chatterid: "5625665ba40e3cbef58de56a758d373d"}' data-type="select" data-value="neutral" id="sentiment_editable1" style="cursor:pointer" >neutral</a>
</span></td></tr>
<tr>
<td width=60%>
<span class="socialcontent1bold">Mood: </span>
<span class="socialcontent1">
<a data-original-title="Select sentiment" data-pk="1" data-url="/Handler" data-params='{chatterid: "fff3878b2d0e6849e9ee8408e7999892"}' data-type="select" data-value="neutral" id="sentiment_editable2" style="cursor:pointer" >neutral</a>
</span></td></tr>
</table>
</div><br/>
</div>
</div>
</div>
弹出窗口中的html需要能够在自己的上下文中运行,就好像它在哪里被隔离而不知道它是用window.open创建的。因此,请确保首先确保popup.html正常工作,然后尝试使用window.open打开它。
答案 1 :(得分:0)
通过你的代码看起来你想让所有14个字段同时被编辑。如果你想一次转换所有14个字段,这是不可能的,因为JqueryUI-Editable需要在所有字段上实现相同的类当您从Ajax Call
获取这些字段时,十四个元素以及所有这些元素必须生动地绑定