也许我不能用一行标题来描述我的问题..描述如下..
我用除法做了一个提示符..页面上的html是..
<button id="prompt_open" name="prompt_open">open</button>
<div id="prompt" style="display:none"></div>现在,我通过javascript(jquery)代码在提示符中生成和html的属性。
$("#post_video").click(function () {
var the_prompt = $("#Stuffprompt_main");
the_prompt.css('display', 'block');
var prompt_html = "";
the_prompt.css('top', '95px');
the_prompt.css('position', 'absolute');
the_prompt.css('left', '300px');
the_prompt.css('width', '610px');
the_prompt.css('border', 'thin');
the_prompt.css('background-color', '#FFF');
the_prompt.css('height', 'auto');
the_prompt.css('z-index', '9999');
the_prompt.attr('id', 'post_prompt');
the_prompt.attr('name', 'post_prompt');
var shut_box = "<a id=\"close_prompt_vdo\" name=\"close_prompt_vdo\" class=\"shut\"></a>";
var header = '<div class="header_prompt"><span id="pr" class="prompt_title">Post video of your stuff</span></div>';
var middler = "<form action=\"user_posting/post_video.php\" name=\"posting_photos\" id=\"posting_photos\" method=\"post\" enctype=\"multipart/form-data\">" +
"<div class=\"object_container\">" +
"<textarea name=\"title_postvideo\" id=\"title_postvideo\" class=\"descriptor\" maxlength=\"100\" placeholder=\"Tilte\" style=\"height:30px;\" ></textarea>" +
"<textarea name=\"text_postvideo\" id=\"text_postvideo\" class=\"descriptor\" maxlength=\"200\" placeholder=\"Add some description\" ></textarea>" +
"<div class=\"file_Container\">" +
"<div class=\"text_box_container\">" +
"<textarea name=\"YTB_link\" id=\"YTB_link\" class=\"descriptor\" style=\"float:left;width:75%; border:thin; border-color: #333;\" maxlength=\"200\" placeholder=\"Add link of your video on You tube\"></textarea>" + "<div style=\"float:left; width:120px; height:80px; background-repeat:no-repeat; background-image:url(images/tube_logo.jpg);\"></div></div>" + "<div class=\"gap\"></div>" + "<div class=\"text_box_container\">" + "<textarea name=\"VMO_link\" id=\"VMO_link\" class=\"descriptor\" style=\"float:left;width:75%; border:thin; border-color: #333;\" maxlength=\"200\" placeholder=\"Add link of your video on Vimeo\"></textarea>" + "<div style=\"float:left; width:135px; height:80px; background-repeat:no-repeat; background-image:url(images/vm_logo.jpg);\"></div></div></div><center>" + "<button id=\"post_video_submit\" class=\"base_buttons\" style=\"margin-top:10px;\"></button>" + "</center></div></form>" + "<div class=\"gap\"></div>";
var HTML = shut_box + header + middler;
the_prompt.html(HTML);
$("#close_prompt_vdo").click(function () {
the_prompt.css('display', 'none');
});这是代码第一次运行,即“prompt_open”按钮打开提示,"close me“按钮关闭提示。但是当我第二次点击“打开提示”按钮时,什么也没有发生,也就是没有显示提示。
该怎么办??
发布于 2013-06-25 01:15:04
the_prompt.attr('id','post_prompt');
是邪恶的一条线。你干吗要干那种事?这使得第二次选择var the_prompt作为$("#Stuffprompt_main")是不可能的。
解决此问题的一些可能性:
var the_prompt = $("#Stuffprompt_main");赋值移到click处理程序之外,这样它就不会每次都被执行(并且当id是close-click-handler中的id属性时仍然指向元素
https://stackoverflow.com/questions/17279789
复制相似问题