xajax 并选择

发布于 2024-07-14 22:53:48 字数 1056 浏览 9 评论 0原文

我使用 XAJAX 创建了一些简单的内容,它用 php 脚本创建的一些选项替换了选择控件的内部 HTML。

这在 Firefox 中很好用,但在 IE7 中不起作用。

查看 XAJAX 论坛,我发现 this 基本上说“在 IE 中不起作用” ,使用 div 并将其内部 HTML 替换为完整的 select 语句”

这样做了,一切都很好,只是我有一个 jQuery 选择器在选择控件上工作,但现在它不再工作了。

任何人有任何想法,或者任何人都可以向我指出一个很好的 jQuery 示例,说明如何使用 jQuery 执行 ajax 位,这样我就可以完全放弃 XAJAX 了?


编辑:

<div id=imgselect>
  <select id="images">
   <option value="">Then select an image</option>
  </select>
</div>


Picture Preview:<br><br>

 <div class="img-preview" id='preview'></div>
 <script type='text/javascript'>
   $('#images').change(function() 
   {
     var image = $(this).val();
     var img = $('<img/>').attr('src', image);
    $('#preview').html(img);

    document.getElementById('picsmall').value = image;
    });
</script>

imgselect div 的内容被 AJAX 调用替换时,问题就出现了

I have a bit of simple created with XAJAX, which replaces the innner HTML of a select control with some options created by a php script.

This is fine and dandy in Firefox, but it does not work in IE7.

Looking on the XAJAX forums i found this which basically says " doesnt really work in IE, use a div and replace the inner HTML of that with the full select statement"

Did this, and it's fine, except that i had a jQuery selector working on the select control, which now no longer works.

Anyone got any ideas, or can anyone point me to a good jQuery example of how to do the ajax bit using jQuery, so I can ditch the XAJAX altogether?


EDIT:

<div id=imgselect>
  <select id="images">
   <option value="">Then select an image</option>
  </select>
</div>


Picture Preview:<br><br>

 <div class="img-preview" id='preview'></div>
 <script type='text/javascript'>
   $('#images').change(function() 
   {
     var image = $(this).val();
     var img = $('<img/>').attr('src', image);
    $('#preview').html(img);

    document.getElementById('picsmall').value = image;
    });
</script>

The problem comes when the contents of the imgselect div is replaced by the AJAX call

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情独悲 2024-07-21 22:53:48

解决了这个问题。

$objResponse->script

现在使用命令

为了完整起见,如果有人想在将来看到,我将原始页面设置为上面:

<div id=imgselect>
  <select id="images">
    <option value="">Then select an image</option>
  </select>
</div>

然后在我的 xajax php 文件中

function getphotos()
{
    $objResponse = new xajaxResponse();
        //this include assigns all the options to the select controll into the $output var
    include "photos.photosselect.php";
    $objResponse->assign("imgselect", "innerHTML", "$output");
    $objResponse->script("$('#images').change(function() {var image = $(this).val(); var img = $('<img/>').attr('src', image); $('#preview').html(img); document.getElementById('picsmall').value = image;});");
    return $objResponse;
}

This is now solved using the

$objResponse->script

command

For the sake of completeness and if anyone wants to see in the future, I have the original page set up as above:

<div id=imgselect>
  <select id="images">
    <option value="">Then select an image</option>
  </select>
</div>

then in my xajax php file I have

function getphotos()
{
    $objResponse = new xajaxResponse();
        //this include assigns all the options to the select controll into the $output var
    include "photos.photosselect.php";
    $objResponse->assign("imgselect", "innerHTML", "$output");
    $objResponse->script("$('#images').change(function() {var image = $(this).val(); var img = $('<img/>').attr('src', image); $('#preview').html(img); document.getElementById('picsmall').value = image;});");
    return $objResponse;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文