下拉选定项目和按钮单击

时间:2023-01-19 08:44:56

Can someone help me with my problem I want to display result depends on the user wants they need to choose on 2 Dropdown list first and then they need to click the button to display the result

有人可以帮我解决我的问题我想显示结果取决于用户想要他们首先需要选择2下拉列表然后他们需要点击按钮显示结果

Here's what I have in html I have 2 Dropdown list and a button

这是我在html中有的2下拉列表和一个按钮

 <div class="col-lg-12">
    <div class="btn-group">
        <button type="button" class="btn btn-warning dropdown-toggle" data-toggle="dropdown">
            Choosy City <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
            <li><a href="#">City 1</a></li>
            <li><a href="#">City 2</a></li>
            <li><a href="#">City 3</a></li>
            <li><a href="#">City 4</a></li>
        </ul>
    </div>
    <div class="btn-group">
        <button type="button" class="btn btn-warning dropdown-toggle" data-toggle="dropdown">
            All Cuisine <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
            <li><a href="#">24 hours</a></li>
            <li><a href="#">American</a></li>
            <li><a href="#">Italian</a></li>
            <li><a href="#">Bar</a></li>
        </ul>
        <button type="button" class="btn btn-danger" style="margin-left: 3px"><i class="fa fa-search"></i></button>
    </div>
</div>

any javascript jquery codes sorry I'm kind of new here

任何javascript jquery代码抱歉我在这里有点新鲜

1 个解决方案

#1


1  

You should use HTML option Tag (see example here with example) instead ul li (as you are beginner) and then use jQuery to get selected value or text.

你应该使用HTML选项Tag(参见这里的示例)而不是ul li(因为你是初学者),然后使用jQuery来获取选定的值或文本。

For example:

HTML:

<select id="optCity">
<option value="MH">Maharastra</option>
<option value="GJ">Gujarat</option>
<option value="MP">Madhya Pradesh</option>
</select>
<button id="btnClick" type="button">Choosy City</button>

jQuery:

$(document).ready(function() {
    $('#btnClick').click(function(event) {
        alert($('#optCity option:selected').text());
    });
});

Here is a demo.

这是一个演示。

Suggestion: You should start some basic learning about jquery from w3cschool.com.

建议:你应该从w3cschool.com开始一些关于jquery的基本知识。

UPDATE2:

here is the answer to your next question.

这是你下一个问题的答案。

$(document).ready(function() {
    $('#btnClick').click(function(event) {
        //alert($('#optCity option:selected').text());
        window.location.assign("your url here");
    });
});

Here is a demo.

这是一个演示。

#1


1  

You should use HTML option Tag (see example here with example) instead ul li (as you are beginner) and then use jQuery to get selected value or text.

你应该使用HTML选项Tag(参见这里的示例)而不是ul li(因为你是初学者),然后使用jQuery来获取选定的值或文本。

For example:

HTML:

<select id="optCity">
<option value="MH">Maharastra</option>
<option value="GJ">Gujarat</option>
<option value="MP">Madhya Pradesh</option>
</select>
<button id="btnClick" type="button">Choosy City</button>

jQuery:

$(document).ready(function() {
    $('#btnClick').click(function(event) {
        alert($('#optCity option:selected').text());
    });
});

Here is a demo.

这是一个演示。

Suggestion: You should start some basic learning about jquery from w3cschool.com.

建议:你应该从w3cschool.com开始一些关于jquery的基本知识。

UPDATE2:

here is the answer to your next question.

这是你下一个问题的答案。

$(document).ready(function() {
    $('#btnClick').click(function(event) {
        //alert($('#optCity option:selected').text());
        window.location.assign("your url here");
    });
});

Here is a demo.

这是一个演示。