【发布时间】:2013-07-06 00:32:17
【问题描述】:
这里是 Jquery Chosen Plugin 的页面(和演示)。这很方便。
http://harvesthq.github.io/chosen/
所以我的问题是我使用 2 阶段输入表单来收集位置信息。 第一个选择菜单是针对国家/地区的。选择国家后,第二个输入字段仅在字段 1 中显示该国家/地区的选项。Neato!
这是我的问题的现场演示。
您会注意到 ajax 调用有效,但是一旦返回第二个字段,样式就会丢失! =(
根据插件
选择菜单必须在某个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>
【问题讨论】:
-
注意 HTML 元素已被替换,因此您的 css 样式停止工作
-
@raam86 有没有办法刷新 css 以在新的 html 上发挥它的魔力?
-
CSS 总是有效的,它很神奇。您的新元素不带有相同的类等,因此 CSS 不适用于它们
-
@raam86 你建议我做什么?
标签: javascript jquery css ajax