CS174
Chris Pollett
Nov 9, 2020
var str = "Rabbits are furry"; var position = str.search(/bits/); /* returns position of first occurrence */
/yx{5}z/ matches yxxxxxz
/Apple/i would match APPLE, aPple and apple.
var str="Fred, Freddie, Frederica"; str.replace(/Fre/g, "Boyd");notice we use g to replace all occurrences.
var str= "3 and 4"; var matches = str.match(/\d/g); //returns [3, 4]
var str="grapes:apples:oranges" var fruit = str.split(":"); // [grapes, apples,oranges]
Which of the following statements is true?
<input type="button" name="turnItOn" />then it could be accessed with document.forms[0].elements[0].
<input type="button" id="turnItOn" name="turnItOn"/>
button = document.getElementById("turnItOn");
myForm = document.getElementById("bob"); numButtons = myForm.vehicles.length; // if we want to we could cycle over this array for values. for( i =0 ; i < numButtons; i++) { oneVehicle = myForm.vehicles[i]. // do something }
<input type = "button" id="b" name="b" onclick="alert('b tapped');" />
document.getElementByID("b").onclick = myNewHandler;
<input type="text" id="cost" onfocus="this.value=10; this.blur();" />
<form ... onsubmit="return checkSubmit()" >
phoneStar = document.getElementById("phoneStar"); phoneStar.style.display="inline";
myelement.addEventListener("change", myhandler, false).
<p style="position: absolute; left:100px; top: 200px">some text </p> <p style="position: relative; left:10px; top: -20px; width: 50">some other text </p>