【问题标题】:Dropdown menu for style switcher样式切换器的下拉菜单
【发布时间】:2015-11-26 13:38:56
【问题描述】:

我需要在我的 mvc 模型上创建一个下拉列表菜单。样式切换器和按钮一样正常工作:

<form>
            <input type="submit" onclick="switch_style('Ugly Default'); return false;" name="theme" value="Ugly_Default" id="Ugly_Default">
            <input type="submit" onclick="switch_style('Redmond'); return false;" name="theme" value="Redmond" id="Redmond">
</form>

链接如下:

<link rel="stylesheet" type="text/css" href="http://localhost:57172/Content/site.css" title="Ugly_Default" >
     <link rel="alternate stylesheet" type="text/css" href="http://localhost:57172/Content/Redmond.css" title="Redmond">
     <script type="text/javascript" src="http://localhost:57172/Scripts/styleswitcher.js"></script>

到目前为止,我已经想出了这个解决方案,但没有效果:

<form name="theme" id="theme" onsubmit="return false;">
        <select id="colourselector" name="theme" onchange="switch_style();">
            <option value="Ugly_Default">Default</option>
            <option value="Redmond">Redmond</option>
        </select>
</form>

任何建议将不胜感激。提前致谢!

【问题讨论】:

  • 函数'switch_style'需要一个参数(样式)。你应该重写它或创建一个新函数。

标签: javascript css razor


【解决方案1】:

我认为你应该这样做:

$(document).ready(function(){
  $('#colourselector').on('change', function(){
    switch_style($(this).val());
  });
});

(需要 Jquery)

【讨论】:

  • 谢谢伙计,它有点工作,但不是普遍的。它只会将主题更改为默认值。检查元素的错误是: Uncaught ReferenceError: $ is not defined (关于 $(document).ready(function () { ) 我有 jQuery...
  • 这个错误意味着'$'没有被定义。表示 Jquery 尚未包含在内。我给出的代码应该放在 Jquery 之后
  • 你是对的。非常感谢你!事实上,我确实忘记在标题中包含 jQuery,现在它就像一个魅力!
  • 请验证答案:)
  • 抱歉,我的印象是我不能投票 = 不能验证答案。现在完成。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-17
  • 2011-07-30
  • 2013-02-23
  • 1970-01-01
相关资源
最近更新 更多