【问题标题】:select from drop down list and color picker according to div properties根据 div 属性从下拉列表和颜色选择器中选择
【发布时间】:2011-03-22 10:55:08
【问题描述】:

我想根据 div 的 title 属性为下拉列表设置选定的项目,并使用 jQuery 设置颜色选择器的选定颜色(div 的样式="background-color: ...")。

我的源代码(来自 Firebug):

<div class = "rsApt" title ="sql"></div>
<div style="background-color: rgb(0, 255, 51);" class="rsAptOut">
  <select style="width: 100px;" 
          id="ddl_editCourse" 
          onchange="javascript:setTimeout('__doPostBack(\'ddl_editCourse\',\'\')', 0)" 
          name="ddl_editCourse">
    <option value="001">oop1</option>
    <option value="002">sql</option>
    <option value="003">WPF</option>
    <option value="004">c#</option>
  </select>
  <div style="width: 261px; z-index: 4000;" 
       class="RadColorPicker RadColorPicker_Default " 
       id="cp_edit">
    <label class="rcpIcon" 
           title="Pick Color (Current Color is blank)"
           id="cp_edit_label">
      <a href="#">Pick Color</a>
      <em style="background-color: rgb(255, 255, 255);" id="cp_edit_icon">(Current Color is )</em>
    </label>
    <input type="hidden" 
           name="cp_edit_ClientState" 
           id="cp_edit_ClientState"
           autocomplete="off" 
           value="{&quot;selectedColor&quot;:null}">
      <div class="rcpPalette" 
           id="cp_edit_palette"
           style="position: absolute; visibility: hidden; width: 259px; left: 107px; top: 75px; display: none;">
    <div class="rcpHeader">
      <a class="rcpEmptyColor" 
         href="#" title="No Color"
         id="cp_edit_emptycolor">
        <span>No Color</span>
      </a>
    </div>
    <div class="rcpViews">
      <div class="rcpPageView" id="cp_edit_webPalette">
        <ul class="rcpWebPalette">
          <li>
            <a class="rcpColorBox" 
               style="background-color: rgb(0, 0, 0);"
               href="#" 
               title="#000000">
              <span style="width: 8px; height: 8px;">#000000</span>
            </a>
          </li>
          <li>
            <a class="rcpColorBox" 
               style="background-color: rgb(0, 0, 51);"
               href="#" 
               title="#000033">
              <span style="width: 8px; height: 8px;">#000033</span></a>
          </li>
          <!-- Additional colors ellided, the list goes on... -->
          <!-- [...] -->
        </ul>
      </div>
    </div>
  </div>
</div>

如何在显示对话框之前执行此操作:

$(document).ready(function() {

  $(".rsAptContent").click(function(e) {
    if ($(e.target).hasClass('rsAptDelete')) {
    }
    else {
        ShowDialog(true);
        e.preventDefault();
    }

});

提前致谢

【问题讨论】:

  • 你能整理一下上面例子中的 HTML 吗?像现在这样尝试阅读它只是一场噩梦。
  • 已编辑,希望有所帮助。
  • 试图让您的 HTML 更具可读性。 (从 Firebug 复制代码并不是 IMO 的最佳做法。)
  • 非常感谢,我知道但试图解释我想做什么,这个问题从昨天开始,没有人回答这个问题:(

标签: javascript html jquery jquery-selectors


【解决方案1】:

也许你会在这里找到提示:jQuery API

$("#ddl_editCourse").change(function () {
      $("#ddl_editCourse option:selected").each(function () {
            $(this).css('backgroundColor', $(".rsApt").css('backgroundColor'));
          });
    })

这只会设置选定的选项。可能您还必须将未选定的选项设置回默认值 - 这您将管理!?

(我没有测试那个代码....)

【讨论】:

  • 谢谢,但它不起作用。我需要在单击我的单元格的内容时,为下拉列表设置选定的值并在以下事件中设置选择器颜色:$(document).ready(function() { $(".rsAptContent").click(function(e) { if ($(e.target).hasClass('rsAptDelete')) { } else { ShowDialog(true); e.preventDefault(); } }); before show dialog () 方法
  • 我在您粘贴的源代码中没有看到类 rsAptContent 的元素..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-11
  • 2018-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-21
  • 2012-07-23
相关资源
最近更新 更多