1 回答

TA貢獻(xiàn)2019條經(jīng)驗 獲得超9個贊
也許是這樣的,閱讀代碼中的注釋
// only run code when "run" has been clicked
$('#run').on('click', function(){
var lines = $('#input').val().split('\n');
if(lines.length <= 1) {
return; // stop here! we don't have two lines to compare!
}
if(lines[0].length < lines[1].length) {
$('#output').val('no');
} else {
$('#output').val('go');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<textarea id="input" rows=2></textarea>
<br>
<textarea id="output" rows=2></textarea>
<br>
<button id='run'>Run code!</button>
添加回答
舉報