0

Jquery Chosen Plugin のページ (およびデモ) は次のとおりです。とても便利です。

http://harvesthq.github.io/chosen/


私の問題は、2段階の入力フォームを使用して位置情報を収集していることです。最初の選択メニューは国向けです。国が選択されると、2 番目の入力フィールドには、フィールド 1 の国のオプションのみが表示されます。

ここに私の問題のライブデモがあります。

http://globatum.com/admin/

ajax 呼び出しは機能しますが、2 番目のフィールドが返されると、スタイリングが失われます。=(

プラグインによると

選択メニューは特定の html フレーム内にある必要があります

    <select data-placeholder="Select City" class="chzn-select" style="width:350px;" tabindex="2" name="city">
<? while($row=mysql_fetch_array($result)) { ?>
<option class="active-result option"
style="padding: 5px 0px 5px 0px; font-family:arial; font-size:12px;"

><?=$row['city']?></option>
<? } ?>
</select>

これは技術的には機能するはずですが、機能しません。呼び出し後にスタイリングを維持する方法についての手がかりはありますか?

返されるphpページは次のとおりです

<!--//---------------------------------+
//  Developed by Roshan Bhattarai    |
//  http://roshanbh.com.np           |
//  Contact for custom scripts       |
//  or implementation help.          |
//  email-nepaliboy007@yahoo.com     |
//---------------------------------+-->
<?
#### Roshan's Ajax dropdown code with php
#### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
#### if you have any problem contact me at http://roshanbh.com.np
#### fell free to visit my blog http://php-ajax-guru.blogspot.com
?>

<? $country = $_GET['country'];
$link  = mysql_connect("SNIP");
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('SNIP');
$query="SELECT city FROM location WHERE country='$country' ORDER BY `city` ASC";
$result=mysql_query($query);

?>
<div class="x">
<br>
<select data-placeholder="Select City" class="chzn-select" style="width:350px;" tabindex="2" name="city">
<? while($row=mysql_fetch_array($result)) { ?>
<option class="active-result option"><?=$row['city']?></option>
<? } ?>
</select>
</div>
4

2 に答える 2

0

liszt:updated2 番目のリストをリロードしたときにイベントをトリガーしようとしましたか? ドコから

Chosen を動的 に更新する 選択フィールドのオプションを更新する必要があり、Chosen に変更を反映させたい場合は、フィールドで "listzt:updated" イベントをトリガーする必要があります。選択されたものは、更新されたコンテンツに基づいて再構築されます。

編集:どこに置くかについてのコメントに応えて、ドキュメントの先頭にある getcity 関数を次のように変更する必要があると思います:

function getCity(country) {
    var strURL="findCity.php?country="+ country;
    var req = getXMLHTTP();
    if (req) {
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if "OK"
                if (req.status == 200) {                        
                    document.getElementById('citydiv').innerHTML=req.responseText;                      
                    $("#citydiv select").trigger("liszt:updated");
                    ///rest of function

これは、都市の div の内容を置き換えた後、理論的には適切な場所でイベントをトリガーする必要があります。

于 2013-07-06T00:56:42.277 に答える