Ich versuche, das C in meinem jQuery-added span-Element anklickbar zu machen, und ich möchte, dass es in F geändert wird, wenn Sie darauf klicken, aber aus irgendeinem Grund funktioniert es nicht.jQuery add klickbaren Buchstaben
$(document).ready(function(){
$("#location").html("<b>New York, NY</b>");
$("#temperature").html("112");
$("#temperature").append("<span> C </span>");
$("span:contains('C')").attr("id", "type");
$("span:contains('C')").click(changeNotation());
});
function changeNotation(){
var notation = document.getElementById("type");
if(notation.textContent == 'C')
notation.innerHTML = 'F';
else if(notation.textContent == 'F')
notation.innerHTML = 'C';
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
<div class="row text-center well">
<h2 class="text-info"> Welcome to the <span><b>Weather App!</span></b></h2>
<p class="text-primary bg-info text-center">
This app will display the weather based on your current location. Click on the C or F to toggle between celcius and fahrenheit.</p>
<h2 class="text-center text-info"><b> Current location </b></h2>
<h1 class="text-center text-info" id="location"> </h1>
<h2 class="text-center text-info"> <b>Current Temperature</b> </h2>
<h1 class="text-center text-info" id='temperature'> </h1>
</div>
</div>
auch ' ' machen brauchen eine andere Click-Ereignis benötigen. Ich erzähle über Wetter App! –
Masiama
und um das Ereignis onclick in jquery hinzuzufügen, müssen Sie '$ (" span: contains ('C') "). On ('click', changeNotation);' – Masiama
machen und 'span' mit" C " – Masiama