1

過去3日間、この簡単な例を機能させようとしましたが、何をしようとしても、どこが間違っているのか理解できないようです...

HTML:

<input type="text" id="textEntry" /> <button>Go</button>
<ul id="list">
    <li>Text from the input field will appear below</li>
</ul>

jQUERY:

$('button').click(function() {
    $enteredText = $('#textEntry').val();

    if($enteredText.length === 0) {
        alert('PLace an item in the field box');
    } else {        
        $newListItem = $('<li/>').html($enteredText).appendTo('#list');
    }

});

$('li').live('mouseover mouseout', function(event) {
    if(event.type == mouseover) {
        $(this).css('background-color', 'yellow');
    } else {
        $(this).css('backgorund-color', 'transparent'); }
});

最終的に私が探しているのは、ユーザーがテキストフィールドに項目を入力して、既存のリストに追加することです(これは機能します-問題はありません)。次に、ユーザーは特定のエントリにカーソルを合わせると、マウスオーバーで背景が黄色になり、マウスアウトで背景が透明になります(問題)。

どんな助けも膨らむでしょう。

ありがとう。

4

2 に答える 2

1
if (event.type == mouseover)

。という名前の変数はありませんmouseover

于 2012-12-02T14:36:19.887 に答える
1

event.typeは文字列でイベントの名前を与えるので、mouseoverである必要があります"mouseover"

$('li').live('mouseover mouseout', function(event) {
    if(event.type == "mouseover") {
        $(this).css('background-color', 'yellow');
    } else {
        $(this).css('backgorund-color', 'transparent'); }
});

編集backgorund-colorする必要がありますbackground-color

于 2012-12-02T14:36:53.750 に答える