在动态国家/地区选择中运行java脚本。如何更改状态的默认选择?

时间:2016-02-25 14:20:01

标签: javascript php

美好的一天, 此源现在允许我预选默认国家/地区。但我需要预先选择默认状态。无法弄清楚如何修改脚本。基本上我想将我的PHP代码绑定到选择框形式,并且每个帐户都能够预先选择国家/地区阶段。非常感谢帮助。

// ////////////////这包括JAVA脚本文件TITLED countries.js ///////////////

Fighter

现在我们看看HTML的实现。

from player import Player


# TODO implement fighter stats and attacks

class Fighter(Player):
    """
    Fighter class, a strong warrior that uses meele attacks to face his opponents
    """

    def __init__(self):
        super().__init__(armor_class=10)
        print("\nYou have chosen the path of strength!")
        self._strength += 2
        self._constitution += 2
        self.atk_bonus += 1
        self.atk_dmg += 3

    def hack_and_slash(self):
        from skills import ActiveSkill
        hack_and_slash = ActiveSkill("Hack n' Slash", "A powerful double attack that has a chance of causing bleeding.",
                                     8, 3)
        self.mp -= hack_and_slash.mp_use

    def __str__(self):
        super().__str__()

代码工作正常,我可以预先选择加拿大,但我也希望传递状态变量。无法弄清楚如何修改代码。

1 个答案:

答案 0 :(得分:0)



(defn tribonacci [x](last (reduce
      (fn  [[a b c] n]
          (conj [b c] (+ a b c))) [0 0 1] (range (- x 3)))))

// countries
var country_arr = new Array( "USA", "Canada", "United Kingdom");

// states
var s_a = new Array();
s_a[0]="";
s_a[1]="Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|District of Columbia|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming";
s_a[2]="Alberta|British Columbia|Manitoba|New Brunswick|Newfoundland|Northwest Territories|Nova Scotia|Nunavut|Ontario|Prince Edward Island|Quebec|Saskatchewan|Yukon Territory";
s_a[3]="Barking and Dagenham|Barnet|Barnsley|Bath and North East Somerset|Bedfordshire|Bexley|Birmingham|Blackburn with Darwen|Blackpool|Bolton|Bournemouth|Bracknell Forest|Bradford|Brent|Brighton and Hove|Bromley|Buckinghamshire|Bury|Calderdale|Cambridgeshire|Camden|Cheshire|City of Bristol|City of Kingston upon Hull|City of London|Cornwall|Coventry|Croydon|Cumbria|Darlington|Derby|Derbyshire|Devon|Doncaster|Dorset|Dudley|Durham|Ealing|East Riding of Yorkshire|East Sussex|Enfield|Essex|Gateshead|Gloucestershire|Greenwich|Hackney|Halton|Hammersmith and Fulham|Hampshire|Haringey|Harrow|Hartlepool|Havering|Herefordshire|Hertfordshire|Hillingdon|Hounslow|Isle of Wight|Islington|Kensington and Chelsea|Kent|Kingston upon Thames|Kirklees|Knowsley|Lambeth|Lancashire|Leeds|Leicester|Leicestershire|Lewisham|Lincolnshire|Liverpool|Luton|Manchester|Medway|Merton|Middlesbrough|Milton Keynes|Newcastle upon Tyne|Newham|Norfolk|North East Lincolnshire|North Lincolnshire|North Somerset|North Tyneside|North Yorkshire|Northamptonshire|Northumberland|Nottingham|Nottinghamshire|Oldham|Oxfordshire|Peterborough|Plymouth|Poole|Portsmouth|Reading|Redbridge|Redcar and Cleveland|Richmond upon Thames|Rochdale|Rotherham|Rutland|Salford|Sandwell|Sefton|Sheffield|Shropshire|Slough|Solihull|Somerset|South Gloucestershire|South Tyneside|Southampton|Southend-on-Sea|Southwark|St. Helens|Staffordshire|Stockport|Stockton-on-Tees|Stoke-on-Trent|Suffolk|Sunderland|Surrey|Sutton|Swindon|Tameside|Telford and Wrekin|Thurrock|Torbay|Tower Hamlets|Trafford|Wakefield|Walsall|Waltham Forest|Wandsworth|Warrington|Warwickshire|West Berkshire|West Sussex|Westminster|Wigan|Wiltshire|Windsor and Maidenhead|Wirral|Wokingham|Wolverhampton|Worcestershire|York";


// add parameter stateSelected
function populateStates(countryElementId, stateElementId, stateSelected) {
    var indexSelected = 0;
    var selectedCountryIndex = document.getElementById(countryElementId).selectedIndex;
    var stateElement = document.getElementById(stateElementId);
    stateElement.length = 0; // Fixed by Julian Woods
    stateElement.options[0] = new Option('Select State', '0');
    stateElement.selectedIndex = 0;

    var state_arr = s_a[selectedCountryIndex].split("|");

    for (var i = 0; i < state_arr.length; i++) {
        stateElement.options[stateElement.length] = new Option(state_arr[i], state_arr[i]);
        // find state index
        if (stateSelected && state_arr[i] == stateSelected) {
            indexSelected = i + 1;
        }
    }

    // set default value if stateSelected passed
    if (stateSelected) {
        stateElement.selectedIndex = indexSelected;
    }
}

// add parameter stateSelected
function populateCountries(countryElementId, stateElementId, countrySelected, stateSelected) {
    var indexSelected = 0,
        countryElement = document.getElementById(countryElementId);

    countryElement.length = 0;
    countryElement.options[0] = new Option('Select Country', '0');
    countryElement.selectedIndex = 0;

    for (var i = 0; i < country_arr.length; i++) {
        countryElement.options[countryElement.length] = new Option(country_arr[i], country_arr[i]);
        if (countrySelected && country_arr[i] == countrySelected) {
            indexSelected = i + 1;
        }

    }

    if (stateElementId) {
        if (countrySelected) {
            countryElement.selectedIndex = indexSelected;
            // call with parameter stateSelected
            populateStates(countryElementId, stateElementId, stateSelected);
        }
        countryElement.onchange = function() {
            populateStates(countryElementId, stateElementId);
        };
    }

    if (countrySelected) {
        countryElement.selectedIndex = indexSelected;
    }
}

// now you can call populateCountries with state
populateCountries("country", "state", "Canada", "Newfoundland");
&#13;
&#13;
&#13;