私はquery parameter
を検索しようとしていますが、input
フィールドでビルドできましたが、他の値を選択するにはselect
ドロップダウンメニューがあります。私はselect
から値を取得し、私の入力にconsole.log出力にそれを同様の方法を構築することができますどのようにqueryStringを作成するjquery selectオプション
function buildQuery(){
var result = "?";
var getVal = $('input#dd').val();
console.log('Input > ', getVal);
var getSelectVal = $('select#sel').val();
if (getVal != null && (getVal != "")) {
let inputValues = getVal
.split("\n")
.filter(function (str) { return str !== "" })
.join("&test=");
// then add it to the overall query string for all searches
result = result + 'test' + "=" + inputValues + "&";
console.log('Results > ', result);
}
わからないクエリのparamを構築するクエリの
<input type="text" id="dd">
<select name="" class="sel">
<option value=""></option>
<option value="Prepare">Prepare</option>
<option value="Ready">Ready</option>
<option value="Cancel">Cancel</option>
</select>
<button onclick="buildQuery()">Build query</button>
jQueryのコードResults > ?test=f&
したがって、input
とselect
のオプションを入力すると、queryParamは?test=inputVal&test=selectVal
、または?test=inputVal
またはのようになります。 0
if()
文全体をコピーし、getVal
をgetSelectVal
に置き換えてください。ただし、効率が悪く、コードが重複しているようです。
実際のコード -
newSearchParams.properties.forEach(function (inputSearch) {
// first reparse the input values to individual key value pairs
// Checks which field is not null and with empty string (space)
var getVal = $('textarea.input_' + inputSearch.name).val();
var getSelectVal = $('select.select_' + inputSearch.name).val();
if (getVal != null && (getVal != "")) {
let inputValues = getVal
.split("\n")
.filter(function (str) { return str !== "" })
.join("&" + inputSearch.name + "=");
// then add it to the overall query string for all searches
result = result + inputSearch.name + "=" + inputValues + "&";
}
}, this);
// remove trailing '&'
result = result.slice(0, result.length - 1);
return result;
試験inputVal&test = selectValは有効です。同じ小道具2の値ですか? –
はい私は試しましたが、選択は有効で適切な値で – MrNew
これはhttps://jsfiddle.net/3wdecqe9/1/を達成しようとしていますか?最後に&記号 –